package com.example.test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Create with Intellij idea
 * User:鲁智明
 * Date:2018/10/14
 * Time:17:32
 */

public class test006 {
    //反射机制执行方法
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        Class<?> forName = Class.forName("com.example.test.test006");
        Object instance = forName.newInstance();
        Method method = forName.getDeclaredMethod("sum", int.class, int.class);
        method.invoke(instance,1,3);
    }

    public static void sum(int a,int b){
        System.out.println("sum:"+(a+b));
    }
}
